

package org.t2.design.module.autogen;


public abstract class AllRechargeAbstractTable<T extends AllRechargeAbstractTable.AllRechargeCfg> extends org.gaming.design.loader.DesignCache<T> {

	@Override
	public final String fileName() {
		return "L-累充返利表";
	}
	
	
	protected java.util.Map<String, T> IdIndex;
	
	/**
	 * 从索引中获取对象，获取不到会抛异常
	 */
	public final T getInIdIndex(
		int Id
	) {
		String key = "" + Id;
		T t = IdIndex.get(key);
		if(t == null) {
			throw new org.gaming.design.exception.DesignNotFoundException("AllRechargeTable when getInIdIndex", key);
		}
		return t;
	}
	
	/**
	 * 从索引中查找对象，获取不到会返回null
	 */
	public final T findInIdIndex(
		int Id
	) {
		String key = "" + Id;
		return IdIndex.get(key);
	}
	
	/**
	 * 加载IdIndex索引
	 */
	private final void loadIdIndex() {
		java.util.Map<String, T> IdIndex = new java.util.HashMap<>();
		for(T data : all()) {
			String[] keys = new String[] {
				String.valueOf(data.getId()),
			};
			String key = String.join("_", keys);
			if(IdIndex.containsKey(key)) {
				logger.error("{} found duplicate key {} in index {}", fileName(), key, IdIndex);
				super.hasError = true;
			}
			IdIndex.put(key, data);
		}
		this.IdIndex = IdIndex;
	}
	
	
	
	protected java.util.Map<String, java.util.List<T>> TypeCollector;
	
	/**
	 * 从容器索引中获取对象，获取不到会抛异常
	 */
	public final java.util.List<T> getInTypeCollector(
		int Type
	) {
		String key = "" + Type;
		java.util.List<T> ts = TypeCollector.get(key);
		if(ts == null) {
			throw new org.gaming.design.exception.DesignNotFoundException("AllRecharge when getInTypeCollector", key);
		}
		return ts;
	}
	
	/**
	 * 从容器索引中查找对象，获取不到会返回null
	 */
	public final java.util.List<T> findInTypeCollector(
		int Type
	) {
		String key = "" + Type;
		return TypeCollector.get(key);
	}
	
	/**
	 * 加载TypeCollector容器索引
	 */
	private final void loadTypeCollector() {
		java.util.Map<String, java.util.List<T>> TypeCollector = new java.util.HashMap<>();
		for(T data : all()) {
			String[] keys = new String[] {
				String.valueOf(data.getType()),
			};
			String key = String.join("_", keys);
			java.util.List<T> datas = TypeCollector.computeIfAbsent(key, k -> new java.util.ArrayList<>());
			datas.add(data);
		}
		this.TypeCollector = TypeCollector;
	}
	
	@Override
	protected final void loadAutoGenerate() {
		//加载索引
		loadIdIndex();
	
		//加载容器索引
		loadTypeCollector();
		
	}
	
	public static class AllRechargeCfg {
		//奖励ID
		protected int Id;
		/**
		 * get奖励ID
		 */
		public int getId() {
			return Id;
		}
		//类型
		protected int Type;
		/**
		 * get类型
		 */
		public int getType() {
			return Type;
		}
		//累充数量
		protected int RechargeNum;
		/**
		 * get累充数量
		 */
		public int getRechargeNum() {
			return RechargeNum;
		}
		//返利物品[物品id,数量]
		protected java.util.List<org.t2.design.struct.RewardThing> Reward;
		/**
		 * get返利物品[物品id,数量]
		 */
		public java.util.List<org.t2.design.struct.RewardThing> getReward() {
			return Reward;
		}
		//排序
		protected int Sort;
		/**
		 * get排序
		 */
		public int getSort() {
			return Sort;
		}
	}

}